#include "L_System.h"

Turtle3D :: Turtle3D(float x, float y, float z, float px, float py, float pz, L_System *l)
	{
		X = x;
		Y = y;
		Z = z;
		phi[0] = px;
		phi[1] = py;
		phi[2] = pz;
		lsys = l;
	}

/*float Turtle :: newY()	
	{						
		float y = (float)(lsys->edgeLength*sin((phi+90)*DEG2RAD));
		Y += y;
		return y;
	}*/

void Turtle3D :: stir(std::string list)
{
		float x;
		float y;
		float z;
		GLfloat m[16];

		//glLoadIdentity();
		
		glTranslatef(1*X, 1*Y, 1*Z);
		glRotatef(phi[0], 1, 0, 0);
		glRotatef(phi[1], 0, 1, 0);
		glRotatef(phi[2], 0, 0, 1);

		for(std::string::iterator it = list.begin(); it != list.end(); it++)
		{
			switch(*it)				//Loop through our input list, applying appropriate
			{						//turtle behavior depending on the symbol received.
				case '&':
					glRotatef(lsys->theta, 1, 0, 0);
					break;
				case '^':
					glRotatef(-lsys->theta, 1, 0, 0);
				case '+':
					glRotatef(lsys->theta, 0, 1, 0);
					break;
				case '-':
					glRotatef(-lsys->theta, 0, 1, 0);
					break;
				case '\\':
					glRotatef(lsys->theta, 0, 0, 1);
					break;
				case '/':
					glRotatef(-lsys->theta, 0, 0, 1);
					break;
				case '|':
					glRotatef(180, 0, 0, 1);
					break;
				case '[':
					//states.push(burial(X, Y, phi));
					glPushMatrix();
					break;
				case ']':
				{
					//resurrection(states.top());
					//states.pop();
					glPopMatrix();
				}	break;
				case '!':
				{
					/*GLfloat* width = (GLfloat*)malloc(sizeof(GLfloat));
					glGetFloatv(GL_LINE_WIDTH, width);
					glLineWidth(*width - 0.1f);
					delete(width);*/
				}
				case 'F':
				{
					/*x = newX();
					y = newY();

					//std::cout << "\n\nNew X: " << x;
					//std::cout << "\nNew Y: " << y << "\n";*/

					glScalef(lsys->edgeLength, lsys->edgeLength, lsys->edgeLength);
					drawLine3D();
					glScalef(1/lsys->edgeLength, 1/lsys->edgeLength, 1/lsys->edgeLength);

					glTranslatef(0, 0, lsys->edgeLength);
					//glTranslatef(0, 0, 1);
	
				}break;
				case 'L':
				{
					drawLeaf3D();
				}
			}

			/*std::cout << "\nSymbol: " << *it;

			glGetFloatv(GL_MODELVIEW_MATRIX, m);
					for(int i = 0; i < 4; i++)
					{
						std::cout << "\n";
						std::cout << m[i] << " ";
						std::cout << m[i+4] << " ";
						std::cout << m[i+8] << " ";
						std::cout << m[i+12] << " ";
					}
					std::cout << "\n";*/
		}
}